package com.example.yadmin.sys.controller;

import com.example.yadmin.common.vo.Result;
import com.example.yadmin.sys.entity.Cart;
import com.example.yadmin.sys.entity.Chat;
import com.example.yadmin.sys.entity.Goods;
import com.example.yadmin.sys.entity.User;
import com.example.yadmin.sys.mapper.ChatMapper;
import com.example.yadmin.sys.service.ICartService;
import com.example.yadmin.sys.service.IGoodsService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ag
 * @since 2023-10-15
 */
@Api(tags = {"购物车接口列表"})
@RestController
@RequestMapping("/cart")
public class CartController {
    @Autowired
    private ICartService cartService;

    //获取所有物品列表
    @GetMapping("/all")
    public Result<List<Cart>> getAllCart() {
        List<Cart> list = cartService.list();
        return Result.success(list, "查询成功");
    }


    //增
    @PostMapping
    public Result<?> addCart(@RequestBody Cart cart){
        cartService.addCart(cart);
        return Result.success("添加购物车成功");
    }

    //改
    @PutMapping
    public Result<?> updateCart(@RequestBody Cart cart){
        cartService.updateCart(cart);
        return Result.success("修改购物车成功");
    }

    //查
    @GetMapping("/{id}")
    public Result<Cart> getCartById(@PathVariable("id")Integer id){
        Cart cart = cartService.getCartById(id);
        return Result.success(cart);
    }

    //删
    @DeleteMapping("/{id}")
    public Result<?> deleteCartById(@PathVariable("id") Integer id){
        cartService.deleteCartById(id);
        return Result.success("移出购物车成功");
    }

    //根据用户名查找用户表单
    @GetMapping("/money")
    public Result<List<User>> getUserMoneyByUsername(@RequestParam(value = "username") String username){
        List<User> list = cartService.getUserMoneyByUsername(username);
        return Result.success(list);
    }


}